package com.phy.mail.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.phy.core.MessageBean;
import com.phy.core.UpdateMap;

/**
 * Servlet implementation class UpdateXML
 */
public class UpdateXML extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String String = null;

	public UpdateXML() {
		super();
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		UpdateMap um = new UpdateMap();
		String content = "thanks for your help.you have update the";
		String type = request.getParameter("type");
		String TextValueOne = request.getParameter("mxabbr");
		String TextValueTwo = request.getParameter("shortinfokeyword");
		//String path = getServletContext().getRealPath("/")+ "xml/map.xml";
		String fileName = request.getSession().getServletContext().getRealPath(
	    "/")+ "WEB-INF/classes/com/phy/core/map.xml";
		// 更新mx记录
		// 取得需要更新的mx记录值
		if (type.equals("mx")) {
			System.out.println("更新mx");
			um.addNode(fileName,TextValueOne, TextValueTwo, "list", "mx", "shortinfo");
			content=content+"mx记录";
		}
		// 更新返回值关键词
		// 取得需要更新的返回值关键词
		else if (type.equals("sys")) {
			System.out.println("更新sys");
			um.addNode(fileName,TextValueOne, TextValueTwo, "sys", "abbr", "keyword");
			content=content+"系统返回值信息";
		}
		PrintWriter out = response.getWriter();
		MessageBean bean = new MessageBean();
		bean.setMessage(content);
		String data = bean.toJson().toString();
		out.print(data);
		System.out.println(data);
		out.flush();
	}

}
